/*****************************************************
 * 空间的操作，通用功能
 *****************************************************/
var sc = sc || {};

/// 适配屏幕解决方案
/// winSize: 设计的分辨率
/// winSizeInPixel: 真实的分辨率
/// originPoint: 左下角原点坐标
/// centerPoint: 中心点的坐标，永远是winSize*.5
/// visiableSize:可视的宽高
/// visiableRect:可视的视角矩形

var ApplicationGameWorld = cc.Class.extend ({
    winSizeInPixel : null,
    winSize:null,
    originPoint:null,
    centerPoint:null,
    visiableSize:null,
    visiableRect:null,
    leftx:null,
    rightx:null,
    topy:null,
    downy:null,

    asp: null,

    init : function () {
        this.winSize = cc.director.getWinSize();
        this.winSizeInPixel = cc.director.getOpenGLView().getFrameSize();

        var asp = this.winSizeInPixel.width / this.winSizeInPixel.height;
        var w = this.winSize.width;
        var h = this.winSize.height;
        if (asp <  w / h) {
            this.originPoint = cc.p((w - h * asp) *.5, 0);
            this.visiableSize = cc.size (h*asp ,h);
        } else {
            this.originPoint = cc.p(0, (h - w/asp) *.5);
            this.visiableSize = cc.size (w, w/asp);
        }
        this.centerPoint = cc.p(w *.5, h *.5);
        this.visiableRect = cc.rect(
            this.originPoint.x,
            this.originPoint.y,
            this.visiableSize.width,
            this.visiableSize.height);
        this.leftx  = this.originPoint.x;
        this.rightx = this.leftx + this.visiableSize.width;
        this.downy  = this.originPoint.y;
        this.topy   = this.downy + this.visiableSize.height;

        this.asp = asp;
    }
});

sc.World = new ApplicationGameWorld ();

/*****************************************************
 * 引擎入口
 *****************************************************/
var MainGameApplication = function () {
    /// 游戏设计分辨率的设计与适配屏幕模式
	cc.view.adjustViewPort(true);
	cc.view.setDesignResolutionSize(960,640,cc.ResolutionPolicy.NO_BORDER);
	cc.view.resizeWithBrowserSize(true);
	cc.director.setProjection(cc.Director.PROJECTION_2D);
    /// 游戏世界视野数据的设定
    sc.World.init();
    /// 游戏入口函数
    GameEnterFunction();
};

/****************************************************
 * 游戏入口函数
 *****************************************************/
var GameEnterFunction = function () {
    cc.loader.loadJs(jsdemoFiles, function (err) {
            var g_resources = [];
            for (var i in RES) {
                g_resources.push(RES[i]);
            }
            cc.Loader.preload(g_resources, function () {
                cc.director.runScene(new MainScene());
            }, this);
        }
    );
};

/******************************************************
 * 预先加载的js文件
 *****************************************************/
var jsdemoFiles = [
    // 功能
    "src/scHelper.js",
    // 资源
    "src/GameRes.js",
    // 主场景
    "src/GameConfig.js",
    "src/GameMain.js",
];

MainGameApplication ();
